﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero2">

    <Style TargetType="{x:Type ComboBox}">
        <Setter Property="Padding" Value="8,0" />
        <Setter Property="Foreground" Value="{DynamicResource ComboBoxForegroundThemeBrush}" />
        <Setter Property="Background" Value="{DynamicResource ComboBoxBackgroundThemeBrush}" />
        <Setter Property="BorderBrush" Value="{DynamicResource ComboBoxBorderThemeBrush}" />
        <Setter Property="BorderThickness" Value="{DynamicResource ComboBoxBorderThemeThickness}" />
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
        <Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False" />
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="FontFamily" Value="{DynamicResource ContentControlThemeFontFamily}" />
        <Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
        <Setter Property="Stylus.IsFlicksEnabled" Value="False" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ComboBox}">
                    <Grid x:Name="templateRoot" SnapsToDevicePixels="True">
                        <Popup x:Name="PART_Popup" AllowsTransparency="True" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Margin="1" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
                            <Themes:SystemDropShadowChrome x:Name="shadow" Color="Transparent" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=templateRoot}">
                                <Border x:Name="DropDownBorder" BorderBrush="{DynamicResource ComboBoxPopupBorderThemeBrush}" BorderThickness="{DynamicResource ComboBoxPopupBorderThemeThickness}" Background="{DynamicResource ComboBoxPopupBackgroundThemeBrush}">
                                    <ScrollViewer x:Name="DropDownScrollViewer">
                                        <Grid x:Name="grid" RenderOptions.ClearTypeHint="Enabled">
                                            <Canvas x:Name="canvas" HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
                                                <Rectangle x:Name="OpaqueRect" Fill="{Binding Background, ElementName=DropDownBorder}" Height="{Binding ActualHeight, ElementName=DropDownBorder}" Width="{Binding ActualWidth, ElementName=DropDownBorder}" />
                                            </Canvas>
                                            <ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                                        </Grid>
                                    </ScrollViewer>
                                </Border>
                            </Themes:SystemDropShadowChrome>
                        </Popup>
                        <ToggleButton x:Name="toggleButton" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.ColumnSpan="2" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">
                            <ToggleButton.Style>
                                <Style TargetType="{x:Type ToggleButton}">
                                    <Setter Property="OverridesDefaultStyle" Value="True" />
                                    <Setter Property="IsTabStop" Value="False" />
                                    <Setter Property="Focusable" Value="False" />
                                    <Setter Property="ClickMode" Value="Press" />
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate TargetType="{x:Type ToggleButton}">
                                                <Border x:Name="templateRoot" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="True">
                                                    <Border x:Name="splitBorder" BorderBrush="Transparent" BorderThickness="1" HorizontalAlignment="Right" Margin="0" SnapsToDevicePixels="True" Width="32">
                                                        <TextBlock x:Name="Arrow" Foreground="{DynamicResource ComboBoxArrowForegroundThemeBrush}" FontWeight="Bold" FontSize="{DynamicResource ComboBoxArrowThemeFontSize}" FontFamily="{DynamicResource SymbolThemeFontFamily}" HorizontalAlignment="Right" IsHitTestVisible="False" Margin="0,0,6,4" Text="&#xE011;" VerticalAlignment="Center" />
                                                    </Border>
                                                </Border>
                                                <ControlTemplate.Triggers>
                                                    <Trigger Property="IsPressed" Value="True">
                                                        <Setter Property="Foreground" TargetName="Arrow" Value="{DynamicResource ComboBoxArrowPressedForegroundThemeBrush}" />
                                                    </Trigger>
                                                    <Trigger Property="IsEnabled" Value="False">
                                                        <Setter Property="Foreground" TargetName="Arrow" Value="{DynamicResource ComboBoxArrowDisabledForegroundThemeBrush}" />
                                                    </Trigger>
                                                </ControlTemplate.Triggers>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </ToggleButton.Style>
                        </ToggleButton>
                        <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" Content="{TemplateBinding SelectionBoxItem}" ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" IsHitTestVisible="False" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="True">
                        </Trigger>
                        <Trigger Property="HasItems" Value="False">
                            <Setter TargetName="PART_Popup" Property="Height" Value="100" />
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsGrouping" Value="True" />
                                <Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="False" />
                            </MultiTrigger.Conditions>
                        </MultiTrigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Background" Value="{DynamicResource ComboBoxDisabledBackgroundThemeBrush}" />
                            <Setter Property="BorderBrush" Value="{DynamicResource ComboBoxDisabledBorderThemeBrush}" />
                            <Setter Property="Foreground" Value="{DynamicResource ComboBoxDisabledForegroundThemeBrush}" />
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Background" Value="{DynamicResource ComboBoxPointerOverBackgroundThemeBrush}" />
                            <Setter Property="BorderBrush" Value="{DynamicResource ComboBoxPointerOverBorderThemeBrush}" />
                        </Trigger>
                        <Trigger Property="CanContentScroll" SourceName="DropDownScrollViewer" Value="False">
                            <Setter Property="Canvas.Top" TargetName="OpaqueRect" Value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}" />
                            <Setter Property="Canvas.Left" TargetName="OpaqueRect" Value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="IsEditable" Value="True">
                <Setter Property="IsTabStop" Value="False" />
                <Setter Property="Padding" Value="2" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ComboBox}">
                            <Grid x:Name="templateRoot" SnapsToDevicePixels="True">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="35" />
                                </Grid.ColumnDefinitions>
                                <Popup x:Name="PART_Popup" AllowsTransparency="True" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
                                    <Themes:SystemDropShadowChrome x:Name="shadow" Color="Transparent" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=templateRoot}">
                                        <Border x:Name="DropDownBorder" BorderBrush="{DynamicResource ComboBoxPopupBorderThemeBrush}" BorderThickness="{DynamicResource ComboBoxPopupBorderThemeThickness}" Background="{DynamicResource ComboBoxPopupBackgroundThemeBrush}">
                                            <ScrollViewer x:Name="DropDownScrollViewer">
                                                <Grid x:Name="grid" RenderOptions.ClearTypeHint="Enabled">
                                                    <Canvas x:Name="canvas" HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
                                                        <Rectangle x:Name="OpaqueRect" Fill="{Binding Background, ElementName=DropDownBorder}" Height="{Binding ActualHeight, ElementName=DropDownBorder}" Width="{Binding ActualWidth, ElementName=DropDownBorder}" />
                                                    </Canvas>
                                                    <ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                                                </Grid>
                                            </ScrollViewer>
                                        </Border>
                                    </Themes:SystemDropShadowChrome>
                                </Popup>
                                <ToggleButton x:Name="toggleButton" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.ColumnSpan="2" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">
                                    <ToggleButton.Style>
                                        <Style TargetType="{x:Type ToggleButton}">
                                            <Setter Property="OverridesDefaultStyle" Value="True" />
                                            <Setter Property="IsTabStop" Value="False" />
                                            <Setter Property="Focusable" Value="False" />
                                            <Setter Property="ClickMode" Value="Press" />
                                            <Setter Property="Template">
                                                <Setter.Value>
                                                    <ControlTemplate TargetType="{x:Type ToggleButton}">
                                                        <Border x:Name="templateRoot" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="True">
                                                            <Border x:Name="splitBorder" BorderBrush="Transparent" BorderThickness="1" HorizontalAlignment="Right" Margin="0" SnapsToDevicePixels="True">
                                                                <TextBlock x:Name="Arrow" Foreground="{DynamicResource ComboBoxArrowForegroundThemeBrush}" FontWeight="Bold" FontSize="{DynamicResource ComboBoxArrowThemeFontSize}" FontFamily="{DynamicResource SymbolThemeFontFamily}" HorizontalAlignment="Right" IsHitTestVisible="False" Margin="0,0,6,4" Text="&#xE011;" VerticalAlignment="Center" />
                                                            </Border>
                                                        </Border>
                                                        <ControlTemplate.Triggers>
                                                            <Trigger Property="IsPressed" Value="True">
                                                                <Setter Property="Foreground" TargetName="Arrow" Value="{DynamicResource ComboBoxArrowPressedForegroundThemeBrush}" />
                                                            </Trigger>
                                                            <Trigger Property="IsEnabled" Value="False">
                                                                <Setter Property="Foreground" TargetName="Arrow" Value="{DynamicResource ComboBoxArrowDisabledForegroundThemeBrush}" />
                                                            </Trigger>
                                                        </ControlTemplate.Triggers>
                                                    </ControlTemplate>
                                                </Setter.Value>
                                            </Setter>
                                        </Style>
                                    </ToggleButton.Style>
                                </ToggleButton>
                                <TextBox x:Name="PART_EditableTextBox" BorderThickness="0" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" IsReadOnly="{Binding IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" Margin="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" />
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="True">
                                </Trigger>
                                <Trigger Property="HasItems" Value="False">
                                    <Setter TargetName="PART_Popup" Property="Height" Value="100" />
                                </Trigger>
                                <MultiTrigger>
                                    <MultiTrigger.Conditions>
                                        <Condition Property="IsGrouping" Value="True" />
                                        <Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="False" />
                                    </MultiTrigger.Conditions>
                                </MultiTrigger>
                                <Trigger Property="IsEnabled" Value="False">
                                    <Setter Property="Background" Value="{DynamicResource ComboBoxDisabledBackgroundThemeBrush}" />
                                    <Setter Property="BorderBrush" Value="{DynamicResource ComboBoxDisabledBorderThemeBrush}" />
                                    <Setter Property="Foreground" Value="{DynamicResource ComboBoxDisabledForegroundThemeBrush}" />
                                </Trigger>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="Background" Value="{DynamicResource ComboBoxPointerOverBackgroundThemeBrush}" />
                                    <Setter Property="BorderBrush" Value="{DynamicResource ComboBoxPointerOverBorderThemeBrush}" />
                                </Trigger>
                                <Trigger Property="CanContentScroll" SourceName="DropDownScrollViewer" Value="False">
                                    <Setter Property="Canvas.Top" TargetName="OpaqueRect" Value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}" />
                                    <Setter Property="Canvas.Left" TargetName="OpaqueRect" Value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Trigger>
            <Trigger Property="Validation.HasError" Value="True">
                <Setter  Property="BorderBrush" Value="{DynamicResource ControlValidationInvalidThemeBrush}" />
            </Trigger>
        </Style.Triggers>
    </Style>
</ResourceDictionary>